/*
package com.lysj.bhp.wallet.job;


import com.lysj.bhp.wallet.base.CoinContent;
import com.lysj.bhp.wallet.domain.EthereumWallet;
import com.lysj.bhp.wallet.util.EtherScanUtil;
import com.lysj.bhp.recharge.domain.RechargeRecord;
import com.lysj.bhp.user.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;

@Component
public class EtherumJob extends CoinContent {

    private static Logger logger = LoggerFactory.getLogger(EtherumJob.class);


    */
/*第一次10秒后执行，当执行完后0.2秒再执行，保证一秒并发不超过5个*//*

    @Scheduled(initialDelay = 10000, fixedDelay = 500)
    public void queryEthereumWallet() {
        logger.info("EthereumJob is Starting ...");
        EthereumWallet ethereumWallet = ethereumWalletRepository.findFirstByOrderByLastQueryTimeAsc();
        if (ethereumWallet == null) {
            return;
        }
        BigInteger queryBalance = EtherScanUtil.getBalance(ethereumWallet.getAddress());
        BigDecimal realBalance = new BigDecimal(""+queryBalance);
        int r = realBalance.compareTo(BigDecimal.ZERO);
        if (r == -1) {  //结果值等于-1表示前者小于后者
            logger.error("EherscanUtil return -1,ethereumWalletId is " + ethereumWallet.getEthereumWalletId());
            ethereumWallet.setLastQueryTime(System.currentTimeMillis());
            ethereumWalletRepository.save(ethereumWallet); // !!!即使发生错误,也应该继续执行下一次的查询!!!
            return;
        }
        int flag = (realBalance.compareTo(ethereumWallet.getBalance()));//查询到的余额小于钱包得真实余额，则更新
        if (flag == -1) {
            ethereumWallet.setBalance(realBalance);
        } else {
            logger.info("EtherWallet Balance Increment,Start Record!" + ethereumWallet.getEthereumWalletId());
            BigDecimal increase = realBalance.subtract(ethereumWallet.getBalance()); // 增加的余额
            User user = userRepository.findOne(ethereumWallet.getUserId());
            user.setEthereumBalance(user.getEthereumBalance().add(increase));
            ethereumWallet.setBalance(realBalance);
            // 创建充值记录
            RechargeRecord rechargeRecord = new RechargeRecord();
            rechargeRecord.setCoinType(2);
            rechargeRecord.setPayAmount(increase.doubleValue());
            rechargeRecord.setUserId(ethereumWallet.getUserId());
            rechargeRecord.setCreateTime(new Date());
            rechargeRecordRepository.save(rechargeRecord);
            userRepository.save(user);
        }
        ethereumWallet.setLastQueryTime(System.currentTimeMillis()); // 将最近的查询时间设置为现在
        ethereumWalletRepository.save(ethereumWallet);
    }


}
*/
